<template>
  <div>
    <a-drawer
      :width="1300"
      :visible="visible"
      :maskClosable="true"
      @close="onClose"
      :destroyOnClose="true"
      class="room-drawer-right"
      :bodyStyle="{
        padding: 0,
        background: '#f7f7f7',
        height: '100%',
      }"
      :closable="false"
    >
      <a-tabs
        tabPosition="left"
        class="room-tabs"
        v-if="roomList.length > 1"
        v-model:activeKey="activeId"
        @change="changeRoom"
      >
        <a-tab-pane v-for="(item, index) in roomList" :key="item.id">
          <template #tab>
            <div
              class="room-tabs-item"
              :class="item.id === activeId ? 'active-item' : ''"
            >
              {{ `${item.layer_name}/${item.room_name}` }}
            </div>
          </template>
        </a-tab-pane>
      </a-tabs>

      <RoomInfo
        v-if="visible"
        showType="modal"
        menuMode="vertical"
        appSuffix="drawer"
        :pageFrom="pageFrom"
        :villageId="roomDetail.village_id"
        :roomId="roomDetail.id"
        :maxRoomNumber="maxRoomNumber"
        :showSubRoomSelect="true"
        @close="onClose"
      />
    </a-drawer>
  </div>
</template>
<script>
import { defineComponent, reactive, toRefs, watch } from "vue";
import RoomInfo from "./RoomInfo.vue";
import _ from "lodash";

export default defineComponent({
  name: "RoomDetailDrawer",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    // 调取页面
    pageFrom: {
      type: String,
      default: "",
    },
    // 房间详情 至少得包含 village_id id
    detail: {
      type: Object,
      default: () => ({}),
    },
    // 当前楼层最大房源编号 可选
    maxRoomNumber: {
      type: [Number, String],
      default: "",
    },
    // 书签形式
    roomList: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  components: { RoomInfo },
  setup(props, { emit }) {
    const onClose = () => {
      emit("cancel");
    };

    const state = reactive({
      roomDetail: {},
      activeId: 0,
    });

    const changeRoom = (key) => {
      state.roomDetail = props.roomList.filter((v) => v.id == key)[0];
    };

    watch(
      () => props.visible,
      (val) => {
        if (val) {
          state.activeId = props.detail.id || props.roomList[0]?.id;
          state.roomDetail = _.cloneDeep(props.detail);
        } else {
          state.activeId = 0;
          state.roomDetail = {};
        }
      },
      { deep: true, immediate: true }
    );

    return {
      ...toRefs(state),
      onClose,
      changeRoom,
    };
  },
});
</script>

<style lang="less" scoped>
.room-tabs {
  height: 100%;
  position: absolute;
  top: 0;
  left: -66px;
  :deep(.ant-tabs-tab) {
    width: 66px;
    padding: 0 !important;
    display: flex !important;
    justify-content: right;
    .room-tabs-item {
      width: 100%;
      padding: 4px 6px !important;
      background-color: #fff;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      word-break: break-all;
      border-top-left-radius: 4px;
      border-bottom-left-radius: 4px;
    }
  }
  :deep(.ant-tabs-ink-bar) {
    display: none !important;
  }
  :deep(.ant-tabs-ink-bar-animated) {
    display: none !important;
  }
}
:deep(.ant-drawer-content) {
  overflow: initial;
}
:deep(.ant-drawer-wrapper-body) {
  overflow: initial;
}
:deep(.ant-tabs-left-bar) {
  border-right: none !important;
}
:deep(.ant-tabs-tab-prev) {
  width: 36px !important;
  right: 0 !important;
  left: initial !important;
  &:hover {
    color: @primary-color;
  }
}
:deep(.ant-tabs-tab-next) {
  width: 36px !important;
  &:hover {
    color: @primary-color;
  }
}
.active-item {
  width: 100% !important;
  background-color: @primary-color!important;
  color: #fff;
}
:deep(.ant-tabs-nav-wrap) {
  padding-top: 10px;
}
</style>

<style lang="less">
.room-drawer-right {
  .ant-drawer-content {
    overflow: initial !important;
  }
  .ant-drawer-wrapper-body {
    overflow: initial !important;
  }
}
</style>
